home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2003 August / MW 8 2003 CD1.iso / Inside Macworld / Product News / gimp-1.2.4.sit / gimp-1.2.4 / plug-ins / perl / examples / fire < prev    next >
Encoding:
Text File  |  2000-07-15  |  3.8 KB  |  117 lines

  1. #!/usr/bin/perl
  2.  
  3. use Gimp;
  4. use Gimp::Fu;
  5.  
  6. N_"/Xtns/Render"; N_"/Xtns/Render/Logos"; # i18n workaround
  7.  
  8. sub fire {
  9.    my ($image, $drawable, $threshold, $strength, $gradient, $displace) = @_;
  10.  
  11.    my ($w,$h) = ($drawable->width, $drawable->height);
  12.  
  13.    $drawable->is_layer or die "sorry, this function needs to call functions that work only for layers :(\n";
  14.  
  15.    $image->undo_push_group_start;
  16.    $drawable->wind($threshold, 0, $strength, 0, 1);
  17.    $drawable->wind($threshold, 1, $strength, 0, 1);
  18.    $drawable->layer_rot270;
  19.    $drawable->wind($threshold, 0, $strength, 0, 1);
  20.    $drawable->wind($threshold, 1, $strength, 0, 1);
  21.    $drawable->layer_rot90;
  22.    $drawable->gauss_rle(($w**2+*$h**2)**0.5*0.003+1,1,1);
  23.    $drawable->desaturate if $drawable->is_rgb;
  24.    $drawable->ripple($w*0.05,$w*0.002,0,2,1,1,0);
  25.    $drawable->ripple($h*0.05,$h*0.002,1,2,1,1,0);
  26.    $drawable->displace($w*0.05,$w*0.05,1,1,$drawable,$drawable,BLACK) if $displace;
  27.    $drawable->c_astretch;
  28.    $drawable->map_to_gradient($gradient);
  29.    $image->undo_push_group_end;
  30.  
  31.    ();
  32. }
  33.  
  34. register "fire",
  35.      "Create a burning (depending on the gradient) halo around an object.",
  36.      "=pod(DESCRIPTION)",
  37.      "Marc Lehmann <pcg\@goof.com>",
  38.      "Marc Lehmann",
  39.      "19990802",
  40.      N_"<Image>/Filters/Colors/Fire...",
  41.      "*",
  42.      [
  43.           [PF_SLIDER,    "threshold",    "Intensity at which to start smearing", 10, [0,255,1]],
  44.           [PF_SLIDER,    "strength",    "The strength (length) of the bursts", 30, [1,300,5]],
  45.           [PF_GRADIENT,    "gradient",    "The gradient to use for the colour, e.g. 'Incandescent' or 'Burning_Paper'", 'Burning_Transparency'],
  46.           [PF_TOGGLE,    "displace",    "Additionally displace with itself?", 0],
  47.          ],
  48.          [],
  49.          ['gimp-1.1'],
  50.          \&fire;
  51.  
  52. register "firetext",
  53.      "Create a burning (depending on the gradient) halo around a string (see <Image>/Filters/Color/Fire).",
  54.      "=pod(DESCRIPTION)",
  55.      "Marc Lehmann <pcg\@goof.com>",
  56.      "Marc Lehmann",
  57.      "19990802",
  58.      N_"<Toolbox>/Xtns/Render/Logos/Firetext...",
  59.      undef,
  60.      [
  61.           [PF_TEXT,    "text",        "The text to render (can be multi-line)", "burn,\nBurn,\nBURN!"],
  62.           [PF_FONT,    "font",        "The font to use"],
  63.           [PF_TOGGLE,    "inverse",    "Invert source mask?", 1],
  64.           [PF_SLIDER,    "strength",    "The strength (length) of the bursts", 10, [1,300,5]],
  65.           [PF_GRADIENT,    "gradient",    "The gradient to use for the colour, e.g. 'Incandescent' or 'Burning_Paper'", 'Burning_Transparency'],
  66.           [PF_TOGGLE,    "displace",    "Additionally displace with itself?", 0],
  67.          ],
  68.          [PF_IMAGE],
  69.          ['gimp-1.1'],
  70.      sub {
  71.    my ($text, $font, $inverse, $strength, $gradient, $displace) = @_;
  72.  
  73.    $text =~ s/[\r\n]+$//;
  74.    
  75.    if ($inverse) {
  76.       Palette->set_foreground('black');
  77.       Palette->set_background('white');
  78.    } else {
  79.       Palette->set_foreground('white');
  80.       Palette->set_background('black');
  81.    }
  82.  
  83.    my ($w,$h) = Gimp->text_get_extents_fontname($text, xlfd_size $font, $font);
  84.    my $image = new Image $w+40, $h+40, RGB;
  85.  
  86.    $image->undo_disable;
  87.    
  88.    my $layer = new Layer $image, $w+40, $h+40, RGBA_IMAGE, "text layer", 100, NORMAL_MODE;
  89.    $layer->fill(BG_IMAGE_FILL);
  90.    $layer->add_layer(0);
  91.    $layer->text_fontname(20,20, $text,0, 1, xlfd_size $font, $font)->anchor;
  92.  
  93.    fire($image,$layer,5,$strength,$gradient,$displace);
  94.  
  95.    Palette->set_foreground('black');
  96.    $image->text_fontname(-1,20-10*$displace,20-10*$displace, $text,0, 1, xlfd_size $font, $font);
  97.  
  98.    $image->undo_enable;
  99.    $image->clean_all;
  100.  
  101.    ($image);
  102. };
  103.  
  104. exit main;
  105.  
  106. =head1 DESCRIPTION
  107.  
  108. This plug-in creates a kind of "burning" effect around a drawable. Both
  109. black-on-white and white-on-black source images make sense and create
  110. different effects (do not use displace with black-on-white drawables,
  111. though ;).
  112.  
  113. Although the original colour of the image does not matter, supplying a
  114. greyscale drawable (though working) does not look very cool.
  115.  
  116. =cut
  117.